<?php

namespace app\modules\weixin\controllers;

use app\common\services\StaticServices;
use app\models\IntegralGood;
use app\models\IntegralRecord;
use app\models\Member;
use app\models\Project;
use app\modules\weixin\controllers\common\BaseController;
use Yii;
use yii\base\Exception;
use yii\web\Response;

class GoodsController extends BaseController {
  /**
   * 动态列表
   * @return array
   */
  public function actionProjectList()
  {
    Yii::$app->response->format = Response::FORMAT_JSON;
    try {
      $p = intval(Yii::$app->request->get('p', 1));
      $good_list = Project::find();

      $page_size = 6;
      $total_count = $good_list->count();
      $total_page = ceil($total_count / $page_size);

      $list = $good_list->offset(($p - 1) * $page_size)->orderBy(['create_time' => SORT_DESC])->limit($page_size)->all();
      return ['code' => 200, 'data' => $list, 'total_page' => $total_page];
    } catch (Exception $e) {
      return ['code' => -200, 'msg' => $e->getMessage()];
    }
  }


  public function actionProjectInfo()
  {
    if (Yii::$app->request->isPost) {
      Yii::$app->response->format = Response::FORMAT_JSON;
      try {
        $pro_id = intval(Yii::$app->request->post('id', 0));
        if ($pro_id) {
          $pro_info = Project::find()->where(["id" => $pro_id])->one();

          return ['code' => 200, 'msg' => $pro_info];
        }
      } catch (Exception $e) {
        return ['code' => -200, 'msg' => $e->getMessage()];
      }
    }
  }
}
